package itheima.d10;

import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public class Test {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dtf.format(now);
        System.out.println(format);

        TemporalAccessor parse = dtf.parse("2020-09-01 12:12:12");
        System.out.println(parse);


        LocalDateTime now1 = LocalDateTime.now();

        String format1 = now1.format(dtf);
        System.out.println("格式化后的时间："+format1);

        LocalDateTime parse1 = LocalDateTime.parse("2020-09-01 12:12:12", dtf );
        System.out.println("字符串时间解析或日期对象："+parse1);
    }
}
